$(function(){
	childrenCompany();
	search();
});

var childrenCompany=function(){
	$.ajax({
		url : contextPath+ 'user/company/childrencompany',
		type : 'POST',
		success : function(list) {
			if(list!=null && list.length>0){
				$("#companyId").empty();
				var option="<option value ='0' >全部单位</option>";
				for(var i=0;i<list.length;i++){
					var company = list[i];
					option +="<option value='"+company.companyId+"'>"+company.companyName+"</option>";
				}
				$("#companyId").append(option);
			}
		}
	});
};

function search(){
	var companyId = $('#companyId').val();
	$.ajax({
		url : contextPath+ 'user/vdystat/listuser',
		data : {
			companyId : companyId
		},
		type : 'POST',
		success : function(list) {
			$("#content").empty();
			if(list!=null && list.length>0){
				var alldyxlcount                  =0;
				var alldyxltotallinelength        =0;
				var alldyxloverheadlinelength     =0;
				var alldyxloverheadlinelengthBar  =0;
				var alldyxloverheadlinelengthCover=0;
				var alldyxlcablelength            =0;
				var alldygtcount                  =0;
				var alllxcount                    =0;
				var allpublicbyqcount             =0;
				var allpublicbyqcapacity          =0;
				var allprivatebyqcount            =0;
				var allprivatebyqcapacity         =0;
				var alldypdxcount                 =0;
				var alldydlfjxcount               =0;
				var alldyzsrdqcount               =0;
				var alldyzskgcount                =0;
				var alldywgbczzcount              =0;
				var alldyzsblqcount               =0;
				var alldyrsxcount                 =0;
				var alldyzsdrqcount               =0;
				var alldyzsdrqcapacity            =0;
				for(var i=0;i<list.length;i++){
					if(companyId=="0"){
					alldyxlcount                   +=list[i].dyxlcount                  ;
					alldyxltotallinelength         +=list[i].dyxltotallinelength        ;
					alldyxloverheadlinelength      +=list[i].dyxloverheadlinelength     ;
					alldyxloverheadlinelengthBar   +=list[i].dyxloverheadlinelengthBar  ;
					alldyxloverheadlinelengthCover +=list[i].dyxloverheadlinelengthCover;
					alldyxlcablelength             +=list[i].dyxlcablelength            ;
					alldygtcount                   +=list[i].dygtcount                  ;
					alllxcount                     +=list[i].lxcount                    ;
					allpublicbyqcount              +=list[i].publicbyqcount             ;
					allpublicbyqcapacity           +=list[i].publicbyqcapacity          ;
					allprivatebyqcount             +=list[i].privatebyqcount            ;
					allprivatebyqcapacity          +=list[i].privatebyqcapacity         ;
					alldypdxcount                  +=list[i].dypdxcount                 ;
					alldydlfjxcount                +=list[i].dydlfjxcount               ;
					alldyzsrdqcount                +=list[i].dyzsrdqcount               ;
					alldyzskgcount                 +=list[i].dyzskgcount                ;
					alldywgbczzcount               +=list[i].dywgbczzcount              ;
					alldyzsblqcount                +=list[i].dyzsblqcount               ;
					alldyrsxcount                  +=list[i].dyrsxcount                 ;
					alldyzsdrqcount                +=list[i].dyzsdrqcount               ;
					alldyzsdrqcapacity             +=list[i].dyzsdrqcapacity            ;
					}
					var div = '<tr height="40">';
					//div += '<ul class="czrz_cont_ul">';
					div += '<td width="4%">'+(i+1)+'</td>';
					div += '<td width="10%">'+list[i].companyName+'</td>';
					div +='<td width="4%">'+list[i].dyxlcount+'</td>';
					div +='<td width="4%">'+list[i].dyxltotallinelength+'</td>';
					div +='<td width="4%">'+list[i].dyxloverheadlinelength+'</td>';
					div +='<td width="4%">'+list[i].dyxloverheadlinelengthBar+'</td>';
					div +='<td width="4%">'+list[i].dyxloverheadlinelengthCover+'</td>';
					div +='<td width="4%">'+list[i].dyxlcablelength+'</td>';
					div +='<td width="4%">'+list[i].dygtcount+'</td>';
					div +='<td width="4%">'+list[i].lxcount+'</td>';
					div +='<td width="4%">'+list[i].publicbyqcount+'</td>';
					div +='<td width="4%">'+list[i].publicbyqcapacity+'</td>';
					div +='<td width="4%">'+list[i].privatebyqcount+'</td>';
					div +='<td width="4%">'+list[i].privatebyqcapacity+'</td>';
					div +='<td width="4%">'+list[i].dypdxcount+'</td>';
					div +='<td width="4%">'+list[i].dydlfjxcount+'</td>';
					div +='<td width="4%">'+list[i].dyzsrdqcount+'</td>';
					div +='<td width="4%">'+list[i].dyzskgcount+'</td>';
					div +='<td width="4%">'+list[i].dywgbczzcount+'</td>';
					div +='<td width="4%">'+list[i].dyzsblqcount+'</td>';
					div +='<td width="4%">'+list[i].dyrsxcount+'</td>';
					div +='<td width="4%">'+list[i].dyzsdrqcount+'</td>';
					div +='<td width="96">'+list[i].dyzsdrqcapacity+'</td>';
					//div += '</ul>';
					div += '</tr>';
					$("#content").append(div);
				}
				if(companyId=="0"){
					var end = '<tr height="40">';
					//end += '<ul class="czrz_cont_ul">';
					end += '<td width="4%">合计</td>';
					end += '<td width="10%"></td>';
					end += '<td width="4%">'+alldyxlcount                  +'</td>';
					end += '<td width="4%">'+alldyxltotallinelength        +'</td>';
					end += '<td width="4%">'+alldyxloverheadlinelength     +'</td>';
					end += '<td width="4%">'+alldyxloverheadlinelengthBar  +'</td>';
					end += '<td width="4%">'+alldyxloverheadlinelengthCover+'</td>';
					end += '<td width="4%">'+alldyxlcablelength            +'</td>';
					end += '<td width="4%">'+alldygtcount                  +'</td>';
					end += '<td width="4%">'+alllxcount                    +'</td>';
					end += '<td width="4%">'+allpublicbyqcount             +'</td>';
					end += '<td width="4%">'+allpublicbyqcapacity          +'</td>';
					end += '<td width="4%">'+allprivatebyqcount            +'</td>';
					end += '<td width="4%">'+allprivatebyqcapacity         +'</td>';
					end += '<td width="4%">'+alldypdxcount                 +'</td>';
					end += '<td width="4%">'+alldydlfjxcount               +'</td>';
					end += '<td width="4%">'+alldyzsrdqcount               +'</td>';
					end += '<td width="4%">'+alldyzskgcount                +'</td>';
					end += '<td width="4%">'+alldywgbczzcount              +'</td>';
					end += '<td width="4%">'+alldyzsblqcount               +'</td>';
					end += '<td width="4%">'+alldyrsxcount                 +'</td>';
					end += '<td width="4%">'+alldyzsdrqcount               +'</td>';
					end += '<td width="96">'+alldyzsdrqcapacity            +'</td>';
					//end += '</ul>';
					end += '</tr>';
					$("#content").append(end);
				}
			}
		}
	});
}

function exportexcle(){
	var companyId = $('#companyId').val();
	if(confirm("确定导出对应数据吗？")){
		$("#exportimg").show();
		$.ajax({
			url : contextPath+ 'user/excel/vdystatlist',
			data : {
				companyId : companyId
			},
			type : 'POST',
			success : function(data) {
				$("#exportimg").hide();
				if(data.opResult=='0'){
					var uploadurl = basePath + data.msgDesc;
					//alert(uploadurl);
					window.location.href = uploadurl;
				}else{
					alert(data.msgDesc);
				}
			}
		});
	}
}
